﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	SqlCommandResult.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;

namespace Smart.Common.Entities
{
	/// <summary>
	/// Result for execute sql command
	/// </summary>
	public class SqlCommandResult
	{
		public int ResultCode { get; set; }

		public string Description { get; set; }

		public SqlCommandResult()
		{
		}

		public SqlCommandResult(SqlItem resultItem, MetaSqlObject meta)
		{
			ParseResultItem(resultItem, meta);
		}

		protected virtual void ParseResultItem(SqlItem resultItem, MetaSqlObject meta)
		{
			if (resultItem == null)
				throw new ArgumentNullException("resultItem");

			if (resultItem.Values.ContainsKey(meta.ResultCodeKey))
			{
				ResultCode = resultItem.Values[meta.ResultCodeKey].SToInt();
			}

			if (resultItem.Values.ContainsKey(meta.ResultDescriptionKey))
			{
				Description = resultItem.Values[meta.ResultDescriptionKey].SToStr();
			}
		}
	}
}